package com.yaodian100.ec.order.service;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.DomainService;
import com.yaodian100.ec.member.entity.Balance;
import com.yaodian100.ec.order.entity.CsrUpdateOrderLog;
import com.yaodian100.ec.order.entity.OrderBonusCampaign;
import com.yaodian100.ec.order.entity.OrderMemo;
import com.yaodian100.ec.order.entity.OrderProduct;
import com.yaodian100.ec.order.entity.OrderProductDetail;
import com.yaodian100.ec.order.entity.Orders;
import com.yaodian100.ec.order.remote.Order;
import com.yaodian100.ec.shopping.entity.CartOrders;

public interface OrderService extends DomainService<Orders> {

	/**
	 * 換貨申請
	 * 
	 * @return
	 * @throws CoreException
	 */
	public boolean changeApply(Long orderProdId) throws CoreException;

	/**
	 * 收費處理
	 * 
	 * @param orderId
	 * @param paymentId
	 * @param amount
	 * @return
	 * @throws CoreException
	 */
	public boolean charge(String orderId, String paymentId, BigDecimal amount) throws CoreException;

	public boolean charge(String orderId, String paymentId, BigDecimal amount, String src);

	/**
	 * 取得當日成立訂單的會員編號
	 * 
	 * @param firstResult
	 * @param maxResults
	 * @return
	 * @throws CoreException
	 */
	public List<String> getAllOrdersMemberId(int firstResult, int maxResults) throws CoreException;

	/**
	 * 取得當日成立訂單的會員編號筆數
	 * 
	 * @return
	 * @throws CoreException
	 */
	public long getAllOrdersMemberIdSize() throws CoreException;

	// 渠道接口channel
	public List<String> getChannelList(String orderId) throws CoreException;

	/**
	 * 依會員查詢訂單
	 * 
	 * @param memberId
	 * @throws CoreException
	 */
	public Collection<Orders> getOrdersByMemberId(String memberId) throws CoreException;

	/**
	 * 依訂單編號查詢訂單
	 * 
	 * @param orderId
	 * @throws CoreException
	 */
	public Orders getOrdersByOrderId(String orderId, String memberId) throws CoreException;

	public Orders getOrder(String orderId);

	public OrderProduct getOrderProduct(Long orderProductId);

	public OrderProductDetail getOrderProductDetail(Long orderDetailId);

	public List<OrderProductDetail> getOrderDetailListByOrderProdId(Long orderProdId);

	public void manualReturnShipfare(String orderId);

	/**
	 * 退費至我的帳戶
	 * 
	 * @return
	 * @throws CoreException
	 */
	public boolean refundToMyAccount() throws CoreException;

	/**
	 * 退貨申請
	 * 
	 * @return
	 * @throws CoreException
	 */
	public boolean returnApply(Long orderProdId, int qty) throws CoreException;

	/**
	 * 退貨申請取消
	 * 
	 * @return
	 * @throws CoreException
	 */
	public boolean returnCancel(Long orderProdId, int qty) throws CoreException;

	public void sendApplyClaimMail(String velocityTemplate, Orders order) throws CoreException;

	public void sendMailForProductArrive(Orders order);

	// public Orders createOrder(CartOrders cart, Map<String, String> addonInfo) throws CoreException;

	public void syncOrder(Orders order);

	/**
	 * 提供後台更新發票資料
	 * 
	 * @param orderId
	 * @param invoiceDt
	 * @param invoiceNumber
	 * @return
	 * @throws CoreException
	 */
	public boolean updateInvoice(String orderId, Date invoiceDt, String invoiceNumber) throws CoreException;

	/**
	 * 修改订单资料
	 * 
	 * @param order
	 * @param logmsg
	 * @return
	 * @throws CoreException
	 */
	public boolean updateOrder(Orders order, String logmsg) throws CoreException;

	/**
	 * 修改订单狀態
	 * 
	 * @param orderId
	 * @param logmsg
	 * @return
	 * @throws CoreException
	 */
	public boolean updateOrderSt(String orderId, String orderStCode) throws CoreException;

	public String updateOrderStatus(Order o);

	/**
	 * @param cartId
	 * @param addonInfo 'coupon': optional, coupon 的 UUID 'couponProduct': optional, 使用 coupon 的 productId 'channelChild':
	 *          'remoteAddr': optional, default: 0.0.0.0
	 * @param payment 'paymentType': require 'bonus': optional, default: 0.00 'vrtBlnc': optional, default: 0.00
	 * @return
	 * @throws CoreException
	 */
	public Orders createOrderWithPay(CartOrders cartObj, Map<String, String> addonInfo, Map<String, String> payment)
			throws CoreException;

	public Orders addPromoteProductAndResync(String orderId, String productId, String categoryPath) throws CoreException;

	public List<OrderProduct> getOrderProdList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	public boolean verifyOrder(String days, String memberId, String orderSt);

	public void csrUpdateOrderAndShipfare(Orders origin, Orders newOrder, String userId, String clientIp, String b2eId,
			List<OrderProduct> cancelProducts);

	public void lockOrderForUpdate(String orderId, String result);

	public void unlockOrder(CsrUpdateOrderLog orderLog);

	public void cancelUnpaidOrderBySystem(Orders order);

	public void remindPayment(Orders order);

	public void completeOrder(String orderId);

	public void remindPaymentSMS(Orders order);

	public Orders addBonusForDelayOrder(String orderId) throws CoreException;

	public Orders revertOrder(String orderId) throws CoreException;

	/**
	 * @param order
	 * @throws CoreException
	 */
	public void cancelOrderByCreditCardNotidy(Orders order) throws CoreException;

	/**
	 * 檢查訂單內的 商品有哪些是大材積
	 * 
	 * @param orderId
	 * @return 商品編號,商品名稱
	 * @throws CoreException
	 */
	public Map<String, String> chkVolumeOfOrderDetail(String orderId) throws CoreException;

	/**
	 * 中台系統人員取消訂單
	 * 
	 * @param order
	 * @param reason
	 * @param memo
	 * @throws CoreException
	 */
	public void cancelOrderBySystemUser(Orders order, String reason, String memo) throws CoreException;

	public Number getOrderMemoSize(CommonCriteria criteria) throws CoreException;

	/**
	 * 查詢訂單讯息
	 * 
	 * @param orderId
	 * @return
	 * @throws CoreException
	 */
	public List<OrderMemo> getOrderMemo(int firstResult, int maxResults, CommonCriteria criteria, String[] sortOrder)
			throws CoreException;

	public OrderMemo saveOrderMemo(OrderMemo orderMemo) throws CoreException;

	/**
	 * 團購成功處理
	 * 
	 * @param tuangouId
	 * @return
	 */
	public List<Orders> processSuccessTuangouOrder(String tuangouId);

	/**
	 * 團購失敗處理
	 * 
	 * @param tuangouId
	 * @return
	 */
	public List<Orders> processFailTuangouOrder(String tuangouId);

	public void cancelOrderByTuangouFail(Orders order) throws CoreException;

	public String remindTuangouClose(Orders order);

	public String splitOrder(String orderId, String orderProdIds);

	// public Orders reCalcBonusAndGiftcardAndMyWallet(Orders order);

	public void saveOrderDetail(OrderProductDetail orderProductDetail) throws CoreException;

	public void saveOrderProd(OrderProduct orderProduct) throws CoreException;

	/**
	 * 修正 order_product / order_detail 之 qty / unit_price 使用 <br>
	 * 正常状况禁止使用
	 * 
	 * @param orderId
	 * @param specId
	 * @param qty
	 * @param price
	 * @param modifyInventory 外部商城不异动库存, 请传 false
	 * @param prodName
	 * @param specName
	 * @param discount
	 * @return
	 * @throws CoreException
	 */
	public Orders updateProduct(String orderId, Long specId, int qty, BigDecimal price, boolean modifyInventory,
			String prodName, String specName, BigDecimal discount) throws CoreException;

	public Orders updateOuterProduct(String orderId, Long specId, int qty, BigDecimal price, boolean modifyInventory,
			String prodName, String specName, BigDecimal discount, String outerCid, String outerProdId, String outerSkuId)
			throws CoreException;

	public Orders addOuterProduct(String orderId, Long specId, int qty, BigDecimal price, boolean modifyInventory,
			String prodName, String specName, BigDecimal discount, String outerCid, String outerProdId, String outerSkuId)
			throws CoreException;

	OrderBonusCampaign saveOrderBonus(OrderBonusCampaign orderBonusCampaign);

	/**
	 * 依訂單金額計算發送的会员积分 應付金額-運費-手續費+帳戶餘額+禮品卡
	 * 
	 * @param order
	 * @param offsetRate
	 * @param offsetUpperLimit
	 * @param offsetDiscountLimit
	 * @return
	 */
	OrderBonusCampaign saveOrderBonusSetting(Orders order, BigDecimal offsetRate, BigDecimal offsetUpperLimit,
			BigDecimal offsetDiscountLimit);

	/**
	 * 计算订单成立后要发送的会员积分
	 * 
	 * @param order price=mustPay-shipfare-codFee-installmentFee+myWallet+giftcardBalance
	 * @param giveBonusSetting
	 * @return
	 */
	BigDecimal calcGiveBonus(Orders order, String giveBonusSetting);

	/**
	 * 计算订单金额可折抵多少会员积分
	 * 
	 * @param domainSrc
	 * @param cookie
	 * @param balance
	 * @param iOffset
	 * @return
	 */
	BigDecimal calcOffsetBonus(String domainSrc, String cookie, Balance balance, BigDecimal orderAmount);

	/**
	 * 计算订单商品的各项费用摊提比例
	 * 
	 * @param order
	 * @return
	 */
	Orders calcOrderProduct(Orders order);

	/**
	 * 第三方支付收款时，原订单分配的mustpay=cash
	 * 
	 * @param order
	 * @return
	 */
	Orders calcOrderCash(Orders order);

	List<OrderProductDetail> getOrderProdDetailList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

}
